<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function quickSort(arr) {
      const length = arr.length
      if(length<=1) return arr
      const middle = Math.floor(length/2)
      const temp = arr[Math.floor(length/2)]
      arr = [...arr.slice(0,middle), ...arr.slice(middle+1)]

      const left = []
      const right = []

      for(let i=0; i<length-1; i++) {
        if(arr[i]<= temp) {
          left.push(arr[i])
        }else{
          right.push(arr[i])
        }
      }

      return [...quickSort(left), temp, ...quickSort(right)]
    }
    console.log(quickSort([32,54,6,8,3,5,6,34,5,6,6,645,3,34,23,12,546,78]))
  </script>
</body>
</html>